import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const releaseList = []
const receiverList = []
const count = 100

for (let i = 0; i < count; i++) {
  // 发布人页面数据 通过用户ID获取此用户发布的任务
  releaseList.push(Mock.mock({
    id: '@increment',
    title: '@title(5, 10)',
    content: Mock.Random.paragraph(10, 15),
    receiverDDId: '@integer(300, 5000)',
    receiverName: '@first',
    // detail: Mock.Random.paragraph(1, 3),
    createTime: '@datetime',
    updateTime: '@datetime',
    'status|1': ['solved', 'geted', 'notget']
  }))
  // 接受人页面数据 查看未领取的任务
  receiverList.push(Mock.mock({
    id: '@increment',
    title: '@title(5, 10)',
    content: Mock.Random.paragraph(10, 15),
    receiverDDId: '@integer(300, 5000)',
    receiverName: '@first',
    publicerDDId: '@integer(300, 5000)',
    publicerName: '@first',
    // detail: Mock.Random.paragraph(1, 3),
    createTime: '@datetime',
    updateTime: '@datetime',
    'status|1': ['solved', 'geted', 'notget', 'finish']

  }))
}

export default {
  getListByPublicerDDId: config => {
    const { page = 1, limit = 20 } = param2Obj(config.url)
    const mockList = releaseList.reverse()
    // if (sort === '-id') {
    //   mockList = mockList.reverse()
    // }
    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      code: 200,
      message: 'success',
      data: {
        rows: pageList,
        total: mockList.length
      }
    }
  },
  getAcceptedListForReceivers: config => {
    const { page = 1, limit = 20 } = param2Obj(config.url)
    const mockList = receiverList.reverse()
    // if (sort === '-id') {
    //   mockList = mockList.reverse()
    // }
    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      code: 200,
      message: 'success',
      data: {
        rows: pageList,
        total: mockList.length
      }
    }
  },
  getDetailById: (config) => {
    const { id } = param2Obj(config.url)
    for (const task of releaseList) {
      if (task.id === +id) {
        return {
          code: 200,
          message: 'success',
          data: task
        }
      }
    }
  },
  getUnacceptedListForReceivers: (config) => {
    const { page = 1, limit = 20 } = param2Obj(config.url)
    const mockList = receiverList.reverse()
    // if (sort === '-id') {
    //   mockList = mockList.reverse()
    // }
    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      code: 200,
      message: 'success',
      data: {
        rows: pageList,
        total: mockList.length
      }
    }
  },
  saveByPublicer: () => {
    return ({
      code: 200,
      message: 'success',
      data: 'success'
    })
  },
  saveByReceiver: () => {
    return ({
      code: 200,
      message: 'success',
      data: 'success'
    })
  },
  receiveTaskById: () => {
    return ({
      code: 200,
      message: 'success',
      data: 'success'
    })
  }
}
